-- check_pos
--
local import = import
---@type behavior_ret
local bret = import("bt/bt_plugin/behavior3/behavior_ret")
---@type math
local math = import("game/func/math")
local M = {
    name = "check_pos",
    type = "Condition",
    desc = "检查角色位置",
    args = {
        { "mapId", "int?", "地图id" },
        { "x", "float?", "x轴" },
        { "y", "float?", "y轴" },
        { "z", "float?", "z轴" },
        { "range", "float?", "据目标点距离" }
    },
    input = { "位置数据?" }
}

function M.run(node, env, value)
    local cfg = node.args
    if value then
        cfg = value
    end
    local mapId = cfg.mapId
    local range = cfg.range
    if not range then
        range = 100
    end
    local owner = env.owner
    if owner.mapId ~= mapId then
        return bret.FAIL
    end
    local dis = math.get_dis_by_pos(owner.pos, cfg)
    if dis <= range then
        return bret.SUCCESS
    end
    return bret.FAIL
end

return M

